package demo0518;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Demo {


        public static void main(String[] args) {
            TestSet testSet = new TestSet();
            Set<Emp> set = new HashSet<>();
            Scanner scanner = new Scanner(System.in);

            boolean flag = true;
            while (flag) {
                System.out.println("欢迎来到员工系统");
                System.out.println("0. 退出系统");
                System.out.println("1. 添加员工");
                System.out.println("2. 查询所有员工");
                System.out.println("3. 根据姓名查询员工信息");
                System.out.println("4. 根据编号删除员工");
                System.out.println("5. 根据员工编号查询");
                System.out.println("6. 根据员工编号修改年龄");
                System.out.print("请选择功能：");

                int n = scanner.nextInt();
                scanner.nextLine();

                switch (n) {
                    case 0:
                        System.out.println("退出系统");
                        flag = false;
                        break;
                    case 1:
                        System.out.println("欢迎来到添加的界面");
                        System.out.print("请输入员工的编号：");
                        String addNumber = scanner.nextLine();
                        System.out.print("请输入员工的姓名：");
                        String addName = scanner.nextLine();
                        System.out.print("请输入员工的年龄：");
                        int addAge = scanner.nextInt();
                        scanner.nextLine(); // 消耗换行符

                        Emp addEmp = new Emp(addNumber, addName, addAge);
                        testSet.addEmp(set, addEmp);
                        System.out.println("员工添加成功，当前员工列表：");
                        testSet.findAllEmp(set);
                        break;
                    case 2:
                        System.out.println("所有员工信息：");
                        testSet.findAllEmp(set);
                        break;
                    case 3:
                        System.out.print("请输入需要查询的员工姓名：");
                        String empName = scanner.nextLine();
                        Emp foundEmp = testSet.findEmpName(set, empName);
                        if (foundEmp != null) {
                            System.out.println("查询结果：" + foundEmp);
                        } else {
                            System.out.println("未找到该员工");
                        }
                        break;
                    case 4:
                        System.out.print("请输入需要删除员工的编号：");
                        String empNumber = scanner.nextLine();
                        testSet.deleteEmp(set, empNumber);
                        System.out.println("删除操作完成，当前员工列表：");
                        testSet.findAllEmp(set);
                        break;
                    case 5:
                        System.out.print("请输入需要查询的员工编号：");
                        String empNumber2 = scanner.nextLine();
                        Emp foundById = testSet.findEmpNumber(set, empNumber2);
                        if (foundById != null) {
                            System.out.println("查询结果：" + foundById);
                        } else {
                            System.out.println("未找到该员工");
                        }
                        break;
                    case 6:
                        System.out.print("请输入需要修改年龄的员工编号：");
                        String empNumber3 = scanner.nextLine();
                        System.out.print("请输入新的年龄：");
                        int age = scanner.nextInt();
                        scanner.nextLine();

                        testSet.changeEmpAge(set, empNumber3, age);
                        System.out.println("修改操作完成，当前员工列表：");
                        testSet.findAllEmp(set);
                        break;
                    default:
                        System.out.println("无效的选择，请重新输入");
                }
                System.out.println();
            }
            scanner.close();
        }
    }